package cn.ac.ict.fpevaluation.cluster.ap;

import cn.ac.ict.fpevaluation.bean.AtomTrajectoryBean;
import cn.ac.ict.fpevaluation.cluster.DataOperationToConsoleUtil;
import cn.ac.ict.fpevaluation.constant.Constant;
import cn.ac.ict.fpevaluation.utils.DataOperationToDiskUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Wu Youxiong on 2017/2/22.
 * <p>
 * AP聚类算法入口
 */
public class APHelper {


    public static List<List<AtomTrajectoryBean>> launch() {
        //从硬盘读取原子轨迹数据
        List<AtomTrajectoryBean> atomTrajectories = DataOperationToDiskUtils.getTrainingData();

        // 1. 对数据进行方向聚类
        System.out.println("1. 方向聚类结果:");
        APBasedDirections apForDirection = new APBasedDirections(atomTrajectories);
        List<List<AtomTrajectoryBean>> afterDirectionCluster = apForDirection.launch();
        // 将方向聚类结果写入硬盘
//        DataOperationToDiskUtils.writeClusterResultToDisk(afterDirectionCluster, Constant.CLUSTER_RESULT_DIRECTION);
        System.out.println("聚类数目:" + afterDirectionCluster.size() + ";\t 详细结果如下:");
        DataOperationToConsoleUtil.printClusterInfo("【基于方向和地磁的AP聚类算法--方向】", afterDirectionCluster);

        List<List<AtomTrajectoryBean>> res = new ArrayList<>();
        // 2. 根据地磁信息进行AP聚类
        System.out.println("2. 地磁聚类结果");
        for (List<AtomTrajectoryBean> list : afterDirectionCluster) {
            APBasedMagnetic ap = new APBasedMagnetic(list);
            List<List<AtomTrajectoryBean>> singleAp = ap.launch();
            res.addAll(singleAp);
        }


        // 3. 将AP聚类结果写入硬盘
        DataOperationToDiskUtils.writeClusterResultToDisk(res, Constant.CLUSTER_RESULT);

        DataOperationToConsoleUtil.printClusterInfo("【基于方向和地磁的AP聚类算法】", res);

        return res;
    }


    public static List<List<AtomTrajectoryBean>> wifiCluster() {
        List<AtomTrajectoryBean> atomTrajectories = DataOperationToDiskUtils.getTrainingData();


        System.out.println("1. WiFi聚类结果:");
        APBasedWifi wifi = new APBasedWifi(atomTrajectories);
        List<List<AtomTrajectoryBean>> res = wifi.launch();

        DataOperationToConsoleUtil.printClusterInfo("【WiFi聚类结果】", res);
        return res;
    }



}
